/*
 * IntroState.cpp
 *
 *  Created on: 19.11.2009
 *      Author: Sergej Schmidt
 */

#include "IntroState.h"
#include "MainMenuState.h"

using namespace Ogre;

IntroState IntroState::m_pIntroState;

void IntroState::enter()
{
	m_pRoot = Root::getSingletonPtr();
	//m_pRenderWindow = m_pRoot->getAutoCreatedWindow();
	m_pSceneMgr = GameManager::getSingleton().getSceneManager();
    m_pCamera = GameManager::getSingleton().getCamera();
    m_pViewport = GameManager::getSingleton().getViewport();
    m_pGui = GameManager::getSingleton().getGui();
    MyGUI::LayoutManager::getInstance().load("intro.layout");

    m_bExitGame = false;
}

void IntroState::exit()
{
	m_pGui->destroyAllChildWidget();
	m_pSceneMgr->clearScene();
	//m_pRoot->getAutoCreatedWindow()->removeAllViewports();
}

void IntroState::pause()
{
	// TODO
}

void IntroState::resume()
{
	// TODO
}

bool IntroState::frameStarted(const FrameEvent& evt)
{
	// TODO
	m_pGui->injectFrameEntered( evt.timeSinceLastFrame );
	return true;
}

bool IntroState::frameEnded(const FrameEvent& evt)
{
	if(m_bExitGame)
		return false;
	return true;
}

void IntroState::keyPressed( const OIS::KeyEvent& e )
{
	// TODO
}

void IntroState::keyReleased( const OIS::KeyEvent& e )
{
    if( e.key == OIS::KC_ESCAPE )
    {
    	m_pViewport->setBackgroundColour( ColourValue( 1.0, 1.0, 1.0 ) );
        m_bExitGame = true;
    }
    if( e.key == OIS::KC_RETURN )
    {
    	// переход к следующему стату
    	changeState( MainMenuState::getInstance() );
    }
}

void IntroState::mouseMoved( const OIS::MouseEvent& e )
{
	m_pGui->injectMouseMove( e.state.X.abs, e.state.Y.abs, e.state.Z.abs );
}

void IntroState::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{
	m_pGui->injectMousePress( e.state.X.abs, e.state.Y.abs, MyGUI::MouseButton::Enum(id) );
	// TODO
}

void IntroState::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{
	m_pGui->injectMouseRelease( e.state.X.abs, e.state.Y.abs, MyGUI::MouseButton::Enum(id) );
    if( id == OIS::MB_Left || id == OIS::MB_Middle )
    {
    	// переход к следующему стату
    	changeState( MainMenuState::getInstance() );
    }
	if(id == OIS::MB_Right)
	{
		m_bExitGame = true;
	}
}
